import java.util.Arrays;
import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-04-12
 * Time: 16:07
 */
public class MyStack {
    private int[] elem;
    private int usedSize;
    public MyStack() {
        this.elem = new int[5];
    }

    public void push(int val) {
        if(isFull()) {
            elem = Arrays.copyOf(elem, 2 * elem.length);
        }
        elem[usedSize] = val;
        usedSize++;
    }

    public boolean isFull() {
        return usedSize == elem.length;
    }
    public int pop() {
        //1. 判断栈不为空
        if(empty()) {
            throw new EmptyException("stack is empty");
        }
        return elem[--usedSize];
    }
    public boolean empty() {
        return usedSize == 0;
    }
    public int pick() {
        if(empty()) {
            throw new EmptyException("stack is empty");
        }
        return elem[usedSize - 1];
    }
}
class MinStack {
    private Stack<Integer> stack;
    private Stack<Integer> minstack;


    public MinStack() {
        this.stack = new Stack<>();
        this.minstack = new Stack<>();
    }

    public void push(int val) {
        stack.push(val);
        if(minstack.empty()) {
            minstack.push(val);
        } else {
            if(val <= minstack.peek()) {
                minstack.push(val);
            }
        }
    }

    public void pop() {
        if(stack.empty()) {
            return;
        }
        int n = stack.pop();
        if(n == minstack.peek()) {
            minstack.pop();
        }
    }

    public int top() {
        if(stack.empty()) {
            return -1;
        } else {
            return stack.peek();
        }
    }

    public int getMin() {
        return minstack.peek();
    }
}
